<template>
  <!-- 分配权限的弹层 -->
  <el-dialog title="新增弹层" :visible="showAssignDialog" @close="closeAssignDialog">
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-form-item label="标签名称" prop="tagname">
        <el-input v-model="form.tagname" placeholder="请输入分类名称" />
      </el-form-item>
    </el-form>
    <template #footer>
      <div style="text-align: right;">
        <el-button @click="closeAssignDialog">取消</el-button>
        <el-button type="primary" @click="addfn">确定</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import { addfnAPI, AddUpdateAPI } from '@/api/tally'
export default {
  props: {
    showAssignDialog: {
      type: Boolean,
      redirect: true
    }
  },
  data() {
    return {
      form: {
        tagname: ''
      },
      rules: {
        tagname: [{ required: true, message: '请输入分类名称', trigger: 'blur' }]
      }
    }
  },
  methods: {
    closeAssignDialog() {
      this.$emit('update:showAssignDialog', false)
      this.$refs.form.resetFields()
      this.form = {
        tagname: ''
      }
    },
    handleChange(value) {
      console.log(value)
    },
    addfn() {
      this.$refs.form.validate(async(flag) => {
        if (flag) {
          if (this.form.id) {
            await AddUpdateAPI(this.form)
            this.$message.success('修改成功')
          } else {
            const res = await addfnAPI(this.form)
            console.log(res)
            this.$message.success('新增成功')
          }
          this.closeAssignDialog()
          this.$parent.PageLiat()
        }
      })
    }
  }
}
</script>

<style>

</style>
